package com.lagou.boot;

import com.lagou.client.RPCConsumer;
import com.lagou.request.RpcRequest;
import com.lagou.service.IUserService;

import java.util.UUID;

public class ConsumerBoot implements Runnable{
    private String hostname;
    private Integer port;

    public ConsumerBoot(String hostname, Integer port) {
        this.hostname = hostname;
        this.port = port;
    }

    public void run() {
        RPCConsumer rpcConsumer = new RPCConsumer();
        IUserService userService = (IUserService)rpcConsumer.createProxy(IUserService.class,hostname,port);

        while (true){
            RpcRequest rpcRequest = new RpcRequest();
            rpcRequest.setRequestId(UUID.randomUUID().toString());
            rpcRequest.setClassName("aaa.bbb.ccc");
            rpcRequest.setMethodName("init");
            rpcRequest.setParameters(new Object[]{"hhh",999});
            rpcRequest.setParamterTypes(new Class[]{int.class,Void.class,Enum.class});

            System.out.println("客户端入参为："+port+rpcRequest.toString());
            String result = userService.sayHello(rpcRequest);
            System.out.println("客户端接收到服务器端的出参为："+result);
            try {
                Thread.sleep(4000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
